package net.pws.common.persistence.jdbc;

import java.util.List;

import net.pws.common.persistence.IPage;

import org.springframework.jdbc.core.RowMapper;


public class JdbcQueryRequest {
    
    /**
     * ����ִ�е�sql
     */
    private StringBuffer sql;
    
    /**
     * ��ѯ����
     */
    private List params;
    
    /**
     *������
     */
    private RowMapper rowMapper;
    
    private int startPageNo;
    
    private int maxResultsInPage;
    
    private JdbcTemplateOracleExtension template;
    
    public RowMapper getRowMapper() {
        return rowMapper;
    }
    
    public JdbcQueryRequest setRowMapper(RowMapper rowMapper) {
        this.rowMapper = rowMapper;
        return this;
    }
    
    public JdbcTemplateOracleExtension getTemplate() {
        return template;
    }
    
    public JdbcQueryRequest setTemplate(JdbcTemplateOracleExtension template) {
        this.template = template;
        return this;
    }
    
    public int getStartPageNo() {
        return startPageNo;
    }
    
    public JdbcQueryRequest setStartPageNo(int startPageNo) {
        this.startPageNo = startPageNo;
        return this;
    }
    
    public int getMaxResultsInPage() {
        return maxResultsInPage;
    }
    
    public JdbcQueryRequest setMaxResultsInPage(int maxResultsInPage) {
        this.maxResultsInPage = maxResultsInPage;
        return this;
    }
    
    public StringBuffer getSql() {
        return sql;
    }
    
    public JdbcQueryRequest setSql(String sql) {
        this.sql = new StringBuffer(sql);
        return this;
    }
    
    public List getParams() {
        return params;
    }
    
    public JdbcQueryRequest setParams(List params) {
        this.params = params;
        return this;
    }
    
    public IPage findByPage() {
        return template.queryByPage(sql.toString(),
                                    params,
                                    startPageNo,
                                    maxResultsInPage,
                                    rowMapper);
    }
    
    public List findByList() {
        return template.queryForList(sql.toString(), params.toArray());
    }
}
